﻿using System;
using System.Text;
using System.ServiceModel;
using System.ComponentModel;
using Sinacor.Infra.UI.Common;
using System.Collections.Generic;
using Sinacor.Infra.UI.Security.Services;
using Sinacor.UI.Bovespa.Corretagem.Communication.Bovespa.Cliente.Cliente;

namespace Sinacor.UI.Bovespa.Corretagem.Communication
{
    public class Cliente: BaseCommunication
    {
       #region Construtor

        public Cliente(SessionInformation sessionInformation)
            : base(sessionInformation)
        {
        }

        #endregion

        #region ConsultarPorApelido

        public Model.Cliente ConsultarPorApelido(Model.Parameter.FiltroClientePorApelido request)
        {
            ICliente servico = null;
            Model.Cliente cliente = new Sinacor.UI.Bovespa.Corretagem.Model.Cliente(); 
            try
            {
                using (ServiceInstance<ICliente> service = new ServiceInstance<ICliente>())
                {
                    servico = service.TryGetInstance(this.Session);
                    cliente = new Translator.DataContractToModel.Cliente().ToCliente( servico.ConsultarPorApelido(new Translator.ModelToDataContract.Cliente().ToFiltroClientePorApelidoRequest(request)));
                }
            }
            catch (Exception ex)
            {
                HandleFault(ex);
            }
            return cliente; 
        }

        #endregion
    }
}
